def func(self, max_tracks, tracks, removed_tracks):
	import random

	results = set()

	most_played = self.getPlayedCount(tracks, False)
	least_played = self.getPlayedCount(tracks, True)

	while most_played > 0 and len(results) < max_tracks:
		batch_max = max_tracks

		batch_tracks = list(self.filterPlayCount(tracks, most_played))

		if len(batch_tracks) == 0:
			most_played -= 1
			if most_played < least_played:
				break
			continue

		if batch_max > len(batch_tracks):
			batch_max = len(batch_tracks)

		random.shuffle(batch_tracks)

		removed = set(batch_tracks[0:batch_max])

		results |= removed

		max_tracks -= len(removed)

		most_played -= 1

		self.stats_played_count(removed, asc = False)

	removed_tracks |= results
